package cn.dyn.funchat.utils;

import io.netty.channel.Channel;
import io.netty.util.AttributeKey;
import org.springframework.stereotype.Component;

/**
 * channel 上下文工具
 */
@Component
public class ChannelContextUtil {
    public void addContext(Long userId, Channel channel) {
        String channelId = channel.id().toString();
        AttributeKey<Long> attributeKey = null;
        if (!AttributeKey.exists(channelId)) {
            attributeKey = AttributeKey.newInstance(channelId);
        } else {
            attributeKey = AttributeKey.valueOf(channelId);
        }
        channel.attr(attributeKey).set(userId);
    }
}
